package com.etc.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.etc.entity.Restaurant;
import com.etc.service.RestaurantService;
import com.etc.utils.CommonMessage;
import com.etc.utils.AjaxLogicBean;
import com.etc.utils.PageData;

@RequestMapping(value="userapi")
@Controller
public class RestaurantController {
	@Resource
	private RestaurantService restaurantService;
	
	@RequestMapping(value="getrestaurant")
	@ResponseBody
	public  AjaxLogicBean<Restaurant>getRestaurant() {
		List<Restaurant> list = restaurantService.getRestaurants();
		AjaxLogicBean<Restaurant> al= new AjaxLogicBean<>();
		al.setData(list);
		return al;
	}
	@RequestMapping("getrestaurantbypage")
	public String getRestaurantBypage(Integer page,Integer limit,Model model){
		if(page==null) {
			page=1;
		}
		if(limit==null) {
			limit=9;
		}
		PageData<Restaurant> pd = new PageData<>();
		List<Restaurant> list = restaurantService.getRestaurantByPage(page,limit);
		int counts=restaurantService.getcount();
		int totalpage=(counts/limit)+1;
		pd.setData(list);
		pd.setLimit(limit);
		pd.setPage(page);
		pd.setCount(totalpage);
		model.addAttribute("pd", pd);
		return "user/restaurant";
	}
}
